﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;
using System.Globalization;
using System.Text;

namespace rpncs {
    public class Settings {
        private const NumberFormatInfo DEFAULT_FORMAT = null;
        public NumberFormatInfo numberFormat {  get; set; }
        private  const int DEFAULT_PLACES = 4;
        public int decimalPlaces {get; set;}
       
        public Settings() {
            numberFormat = CultureInfo.CurrentUICulture.NumberFormat;
            decimalPlaces = DEFAULT_PLACES;
        }

        public Settings( String locale ) {
            decimalPlaces = DEFAULT_PLACES;
            
            numberFormat = CultureInfo.CurrentUICulture.NumberFormat;
        }
        public void setPlaces( int pl ) {
            numberFormat.NumberDecimalDigits = pl;
        }

        public void setDecimalSeparator( String s ) {
            if (s.Equals( "." ) || s.Equals( "," )) {
                numberFormat.NumberDecimalSeparator = s;
            }
        }

        public void setGroupSeparator( String s ) {
            if (s.Equals( "." ) || s.Equals( "," )) {
                numberFormat.NumberGroupSeparator = s;
            }
        }

        public StringBuilder getSettingsAsText() {
            StringBuilder sb = new StringBuilder();
            
            sb.AppendLine( "places=" + numberFormat.NumberDecimalDigits );
            sb.AppendLine( "ds=" + numberFormat.NumberDecimalSeparator );
            sb.AppendLine( "gs=" + numberFormat.NumberGroupSeparator );
            return sb;
        }
    }
}
